﻿using System.IO;

namespace Appology.SugarSync.IO
{
    public static class StreamExtensions
    {
        public static void Copy(this Stream source, Stream target, int bufferSize = 65536)
        {
            int bytesRead;
            byte[] buffer = new byte[bufferSize];

            do
            {
                bytesRead = source.Read(buffer, 0, buffer.Length);

                if (bytesRead > 0)
                {
                    target.Write(buffer, 0, bytesRead);
                    target.Flush();
                }

            } while (bytesRead > 0);

        }
    }
}